using Godot;
using System;
using System.Collections.Generic;

public partial class WeightedTable
{
	// Dictionary<String,Upgrade> currentUpgrades = new Dictionary<string, Upgrade>();
	List<Enemy> items = new List<Enemy>();
	int weightSum = 0;

	public struct Enemy{
		public PackedScene item;
		public int weight;

		public Enemy(PackedScene item,int weight){
			this.item = item;
			this.weight = weight;
		}
	}

	public void AddItem(PackedScene enemy,int weight){

		items.Add(new Enemy(enemy,weight));
		weightSum = weightSum + weight;
	}

	public PackedScene PickItem(){
		int chosenWeight = GD.RandRange(1,weightSum);
		int iterationSum = 0; 
		foreach(Enemy item in items){
			iterationSum += item.weight;
			if(chosenWeight <= iterationSum){
				return item.item;
			}
		}
		return null;
	}

}
